//
//  UICollectionViewDemoViewController.swift
//  swift-practice
//
//  Created by 余振涛 on 2021/7/15.
//

import UIKit

class UICollectionViewDemoViewController: UIViewController,UICollectionViewDataSource, UICollectionViewDelegate {

    var allTagView : UICollectionView!
    var cateAray : Array<Any> = ["1","2","3","4","5","6","7","8","9","10"]
    var allDataArray : Array<Any> = ["射手","战士","法师","坦克","刺客"]
    
    init(withTitle title:String){
        super.init(nibName: nil, bundle: nil)
        self.title = title
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        setupView()
    }
    
    func setupView() {
        let layout = UICollectionViewFlowLayout.init()
        layout.sectionHeadersPinToVisibleBounds = true
        allTagView = UICollectionView.init(frame: self.view.frame, collectionViewLayout: layout)
        allTagView.scrollIndicatorInsets = allTagView.contentInset
        allTagView.delegate = self
        allTagView.dataSource = self
        allTagView.backgroundColor = .white
        allTagView.register(DemoCollectionViewCell.self, forCellWithReuseIdentifier: String(describing: DemoCollectionViewCell.self))
        self.view.addSubview(allTagView)
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return allDataArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = allTagView.dequeueReusableCell(withReuseIdentifier: String(describing: DemoCollectionViewCell.self), for: indexPath) as! DemoCollectionViewCell
        cell.myLabel.text = allDataArray[indexPath.row] as? String
        cell.myLabel.textAlignment = .center
        return cell
    }

}
